﻿using System;
using NUnit.Framework;
using Newtonsoft.Json;

namespace LERP.Tests
{
    public class TestClass
    {
        [Test]
        public void Test()
        {
            string context = "[{\"id\":\"SP0001\",\"name\":\"立白5公斤特惠装洗衣粉\",\"shortname\":\"立白5公斤特惠装洗衣粉\",\"price\":\"255.50\",\"num\":\"10\"},{\"id\":\"SP0002\",\"name\":\"立白清香肥皂\",\"shortname\":\"立白清香肥皂\",\"price\":\"125.60\",\"num\":\"10\"},{\"id\":\"SP0003\",\"name\":\"雕牌5公斤特惠装\",\"shortname\":\"雕牌5公斤特惠装\",\"price\":\"255.50\",\"num\":\"10\"},{\"id\":\"SP0004\",\"name\":\"哇哈哈妞妞牛奶\",\"shortname\":\"哇哈哈妞妞牛奶\",\"price\":\"136.80\",\"num\":\"10\"}]";
            var list =  Newtonsoft.Json.JsonConvert.DeserializeObject<goodsitem[]>(context);
            foreach (var goodsitem in list)
            {
                Console.WriteLine(goodsitem.id+"//"+goodsitem.name+"//"+goodsitem.price+"//"+goodsitem.num);
            }
            //var list = new goodsitem[]
            //               {
            //                   new goodsitem
            //                       {
            //                           id = "SP0001",
            //                           name = "立白5公斤特惠装洗衣粉",
            //                           num = 10,
            //                           price = new decimal(23.65),
            //                           shortname = "立白"
            //                       }, new goodsitem
            //                              {
            //                                  id = "SP0002",
            //                                  name = "立白5公斤特惠装洗衣粉",
            //                                  num = 10,
            //                                  price = new decimal(23.65),
            //                                  shortname = "立白"
            //                              }
            //               };

            //System.Console.WriteLine(JsonConvert.SerializeObject(list));
        }
    }

    public class goodsitem
    {
        //[{"id":"SP0001","name":"立白5公斤特惠装洗衣粉","shortname":"立白5公斤特惠装洗衣粉","price":"255.50","num":"10"},{"id":"SP0002","name":"立白清香肥皂","shortname":"立白清香肥皂","price":"125.60","num":"10"},{"id":"SP0003","name":"雕牌5公斤特惠装","shortname":"雕牌5公斤特惠装","price":"255.50","num":"10"},{"id":"SP0004","name":"哇哈哈妞妞牛奶","shortname":"哇哈哈妞妞牛奶","price":"136.80","num":"10"}]
        [JsonProperty(PropertyName = "id")]
        public string id { get; set; }
        public string name { get; set; }
        public string shortname { get; set; }
        public decimal price { get; set; }
        public int num { get; set; }
    }
}